package dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class ProfissaoDAO {
	
	
	public static ResultSet getProfissao(){
		Connection conn = null;
		PreparedStatement stm = null;
		ResultSet rsProfissao = null;
		
	try {
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost/profissionaisautonomos", "root", "mysql");
		
		String sql = "Select nome from profissao";
		stm = conn.prepareStatement(sql);

		rsProfissao = stm.executeQuery();
		
		/*stm.close();
		conn.close();*/
		
		return rsProfissao;
		
	} catch (SQLException e) {
		System.out.println("sqlexception");
		e.printStackTrace();
	} catch (ClassNotFoundException e) {
		System.out.println("classnofoundexception");
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	return null;
	
	}
	
	
	public static ResultSet getProfissaoByDescricao(String nome){
		Connection conn = null;
		PreparedStatement stm = null;
		ResultSet rsProfissao = null;
		
	try {
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost/profissionaisautonomos", "root", "mysql");
		
		String sql = "Select idProfissao from profissao where nome = '" + nome + "';";
		stm = conn.prepareStatement(sql);

		rsProfissao = stm.executeQuery();
		
		/*stm.close();
		conn.close();*/
		
		return rsProfissao;
		
	} catch (SQLException e) {
		System.out.println("sqlexception");
		e.printStackTrace();
	} catch (ClassNotFoundException e) {
		System.out.println("classnofoundexception");
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	return null;
	
	}
}
